/*
 * LogEx a Java library for extracting log file data
 * Copyright 2012 LogEx Team.
 *
 * This program is free software. You can distribute or modify it under the 
 * terms of the GNU Lesser General Public License version 3.0 as published by  
 * the Free Software Foundation.
 *
 * This program is distributed AS IS and WITHOUT WARRANTY. OF ANY KIND,
 * INCLUDING MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, contact the Free Software Foundation, Inc.,
 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

package org.basex.api;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

public class DatabaseSettings {

	private final String CONFIG_FILE = "config.properties";
	private final String DATABASE_SERVER = "databaseServer";
	private final String DATABASE = "database";
	private final String USER_NAME = "userName";
	private final String PASSWORD = "password";
	private final String PORT = "port";
	private Properties properties = null;

	public DatabaseSettings() {
		this.properties = new Properties();
	}

	/**
	 * Method for getting server name..
	 * 
	 * @return The server name
	 * 
	 * @throws IOException
	 *             If error happens reading the properties file
	 * @throws FileNotFoundException
	 *             If specified file cannot be found
	 */
	public String getDatabaseServer() throws IOException, FileNotFoundException {
		properties.load(new FileInputStream(System.getProperty("user.dir")
				+ File.separator + "Config" + File.separator + CONFIG_FILE));
		return properties.getProperty(DATABASE_SERVER);
	}

	/**
	 * Method for getting database name.
	 * 
	 * @return The database name
	 * 
	 * @throws IOException
	 *             If error happens reading the properties file
	 * @throws FileNotFoundException
	 *             If specified file cannot be found
	 */
	public String getDatabaseName() throws IOException, FileNotFoundException {
		properties.load(new FileInputStream(System.getProperty("user.dir")
				+ File.separator + "Config" + File.separator + CONFIG_FILE));
		return properties.getProperty(DATABASE);
	}

	/**
	 * Method for getting user name.
	 * 
	 * @return The user name
	 * 
	 * @throws IOException
	 *             If error happens reading the properties file
	 * @throws FileNotFoundException
	 *             If specified file cannot be found
	 */
	public String getUserName() throws IOException, FileNotFoundException {
		properties.load(new FileInputStream(System.getProperty("user.dir")
				+ File.separator + "Config" + File.separator + CONFIG_FILE));
		return properties.getProperty(USER_NAME);
	}

	/**
	 * Method for getting password.
	 * 
	 * @return The password
	 * 
	 * @throws IOException
	 *             If error happens reading the properties file
	 * @throws FileNotFoundException
	 *             If specified file cannot be found
	 */
	public String getPassword() throws IOException, FileNotFoundException {
		properties.load(new FileInputStream(System.getProperty("user.dir")
				+ File.separator + "Config" + File.separator + CONFIG_FILE));
		return properties.getProperty(PASSWORD);
	}

	/**
	 * Method for getting the port.
	 * 
	 * @return The port
	 * 
	 * @throws IOException
	 *             If error happens reading the properties file
	 * @throws FileNotFoundException
	 *             If specified file cannot be found
	 */
	public String getPort() throws IOException, FileNotFoundException {
		properties.load(new FileInputStream(System.getProperty("user.dir")
				+ File.separator + "Config" + File.separator + CONFIG_FILE));
		return properties.getProperty(PORT);
	}

}
